<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>讨论章节列表页</title>
		<link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/discuss.css">
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<link rel="stylesheet" href="../../css/base.css">
		<style>
			html body {
				background-color: #F3F5F7;
			}
			.weui_mask {
				position: fixed;
				z-index: 998;
				top: 0;
				right: 0;
				bottom: 0;
				left: 0;
			}
			.weui_dialog {
				z-index: 999;
			}
			.myScore2 {
				background: #fff;
				padding: 20px;
				border-bottom: 1px solid #d9d9d9;
				border-top: 1px solid #d9d9d9;
			}
			.add-btn {
				margin-top: 15px;
				background: #FFFFFF;
				width: 119px;
				height: 35px;
				border: 1px solid #666666;
			}
			.noSign {
				padding-top: 105px;
				padding-bottom: 75px;
				/*background: #FFFFFF;*/
			}
			.mui-btn.mui-active:enabled, .mui-btn:enabled:active, button.mui-active:enabled, button:enabled:active, input[type=button].mui-active:enabled, input[type=button]:enabled:active, input[type=reset].mui-active:enabled, input[type=reset]:enabled:active, input[type=submit].mui-active:enabled, input[type=submit]:enabled:active {
				color: #333;
				background: #F3f5f7;
				border: 1px solid #333333;
			}
			.qusetion-num-normal2 {
				/*	margin: 2px;
				 /* width: 44px;
				 height: 44px;*/
				/*line-height: 14px;
				 text-align: center;*/
			}
		</style>
	</head>
	<body>
		<div id="main_div ">
			<div class=" writeReport " >
				<div class="bgwhite  "  hidden="hidden" id="contentDiv">
					<div class="padding10" id="bewriteDIV"  >
						<p class=" base_black_grey base_title_font">
							描述
						</p>
						<div class="base_dark_grey base_content_font according-2-rows text_indent_2 word-break" id="bewrite" onclick="openBewrite()"></div>
					</div>
					<div class="div_divider"></div>
					<div style="background-color: #f0f0f0;height:15px"></div>
					<div class="padding10" id="bewriteDIV"  >
						<p class=" base_black_grey base_title_font">
							讨论成员
						</p>
						<div class="base_dark_grey base_content_font according-2-rows text_indent_2 word-break" id="people" ></div>
					</div>
					<!--<div class="myScore2  sf_peix">
					<span class="font16 base_dark_grey "style='color: red'id="num">0<span class="font16 base_dark_grey left_5">条</span></span>
					<span class="font16 base_dark_grey left_10" id="theme">讨论</span>
					</div>-->
				</div>
				<div id="commentList">
					<ul class="mui-table-view "id="list_discus">
						<!--	<li dataid="' + index + '" class="mui-table-view-cell mui-media list_item">
						<div onclick="openReplayWin(' + index + ')">
						<img class="mui-media-object mui-pull-left cell_user_icon" src="' + imgStr + '" style="display: block">
						<p class=" base_content_font base_dark_grey" >
						<span> 老网</span>
						<span class="left_5 font10">'
						刚刚 </span>
						</p>
						<div class="Commentbody top_2 ">
						<p class="word-break font12">
						地对地导弹
						</p>
						<p class="word-break left_50">
						地对地导弹
						</p>
						</div>
						</div>
						<table class="MBToolBar top_5 ">
						<tr>
						<td class="Comment" id="Reply" onclick="ReplayDiscus(' + index + ')"><img  src="../../image/icon_huifu.png"  class="incon_samll"><span class="left_5">4</span></td>
						</tr>
						</table>
						</li>-->
					</ul>
					<div class="noSign"  id="noTeam" style="display: none;">
						<p class="font16 top_15 base_dark_grey " style="margin-bottom: 15px">
							您未加入入讨论小组里面
							<br>
							要先创建小组才可以哟~
						</p>
						<img src="../../icon/null_discuss.png" width="60%" >
						<p></p>
						<button type="button" class="mui-btn add-btn" onclick="AddTeamDiscussClick()">
							创建小组
						</button>
					</div>
					<div class="noSign"  id="noData" style="display: none;">
						<img src="../../image/icon_img.png" width="60%">
						<p class="font16 top_15 base_dark_grey" >
							暂无小组讨论
						</p>
					</div>
					<div class="loadFailure" hidden="hidden" id="noNet" style="display: none;">
						<img src="../../image/icon_img01.png" width="60%">
						<p class="" >
							数据加载失败
						</p>
						<p>
							请检查您的网络
						</p>
						<button type="button" class="mui-btn mui-btn-outlined" onclick="refreshData()">
							重新加载
						</button>
					</div>
				</div>
				<div id="offlineAlert" class="weui_dialog_confirm" style="display: none;">
					<div class="weui_mask"></div>
					<div class="weui_dialog">
						<div class="weui_dialog_hd">
							<strong class="weui_dialog_title">确定删除此评论？</strong>
						</div>
						<div class="weui_dialog_bd"></div>
						<div class="weui_dialog_ft">
							<a onclick="cleanCancel()" href="#" class="weui_btn_dialog default"  style="color:#18b4ed">取消</a>
							<a onclick="cleanConfirm()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/push.js"></script>
	<script type="text/javascript">
		var page = 1;
		var row = 10;
		var refreshCount = 0;
		//更新数据条数
		var dataArr = new Array();
		var pid = "";
		// 计划id
		var cid = "";
		//课程id
		var chapterid = "";
		//章节id
		var title = "";
		var is_dis_bewrite = '';
		//被点击的题目id
		var Itemid = "";
		var dataLen = 0;
		apiready = function() {
			var pageParam = api.pageParam;
			pid = pageParam.pid;
			cid = pageParam.cid;
			chapterid = pageParam.chapterid;
			title = pageParam.title;
			bewrite();
			//接收通知
			ReceiveNotifi();
			//开启加载框
			showProgress();
			JudgeType();
			//开始刷新
//			startGroupDiscussUpdate();
		};
		//判断状态
		function JudgeType() {
			loadNewData();
			//下拉加载
			setRefreshHeader();
			//上拉刷新
			setPullUpRefresh();
		}

		//讨论描述详情
		function bewrite() {
			pageParam = api.pageParam;
			$('#nav_title').html(pageParam.title);
			var bewrite = pageParam.bewrite;
			if (bewrite != "" && bewrite != null && bewrite != undefined) {
				$('#bewriteDIV').show();
				if (removeHTMLTag(bewrite).length > 0) {
					$('#bewrite').html(removeHTMLTag(bewrite));
				} else {
					$('#bewrite').text('点击查看详情');
				}
			}
		}

		//创建小组跳转
		function AddTeamDiscussClick() {
			$('#noTeam').hide();
			$('#contentDiv').hide();
			api.openWin({useWKWebView:true,
				name : 'CreateTeam',
				url : '../CourseManage/CreateTeam.html',
				pageParam : {
					pid : api.pageParam.pid,
					cid : api.pageParam.cid,
					vid : api.pageParam.chapterid,
					title : api.pageParam.title,
					bewrite : api.pageParam.bewrite,
				},
				//				reload : true
			});
		}

		//是否退出确定按钮
		function backyes() {
			$('#backAlert').hide();
			api.closeWin({
			});
		}

		//是否退出取消按钮
		function backCancel() {
			$('#backAlert').hide()
		}

		//接收通知刷新列表
		function ReceiveNotifi() {
			//编辑讨论的通知
			api.addEventListener({
				name : 'RefreshSummaryListNotifi'
			}, function(ret, err) {
				loadNewData();
			});
			//添加新的讨论的通知
			api.addEventListener({
				name : 'RefreshPanelDiscussAddDiscusNotifi'
			}, function(ret, err) {
				loadNewData();
			});
			//			//小组讨论关闭的通知
			//			api.addEventListener({
			//				name : 'GroupDiscussUpdateNotifi'
			//			}, function(ret, err) {
			//				loadNewData();
			//			});
			//接受阿里云推送，一旦小组讨论发表总结,刷新页面ui，获取当前小组内所有人的讨论
			api.addEventListener({
				name : 'pushMessageGroupDiscussion'
			}, function(ret, err) {
				var notifiJid = ret.value.jid;
				var DC_TYPE = ret.value.type;
				if (notifiJid == $api.getStorage('cfnetppjxid')) {
					if (ret.value.id == api.pageParam.group_id) {
						if (DC_TYPE == 10056) {
							loadNewData();
						}
					}
				}
			});
			//关闭后刷新列表
			api.addEventListener({
				name : 'closePanelDiscussNotifi'
			}, function(ret, err) {
				loadNewData();
			});
		}

		//加载新数据
		function loadNewData() {
			page = 1;
			loadData();
			//停止刷新控件
		}

		//加载更多数据
		function loadMoreData() {
			page++;
			loadData();
		}

		//存储刷新时间
		function saveTimeStamp() {
			var timestamp = new Date().getTime();
			var timeStampStr = timestamp.toString();
			$api.setStorage('PanelDiscussionLastTimeStamp', timeStampStr);
			$api.setStorage('PanelDiscussionGroupId', api.pageParam.group_id);
			console.log("11111111");
		}

		//判断当前用户名称
		function selectName(user) {
			var showName = "";
			if (user.realname == null) {
				if (user.uname == null) {
					if (user.email == null) {
						if (user.phone == null) {
							showName = "暂无姓名";
						} else {
							showName = user.phone;
						}
					} else {
						showName = user.email;
					}
				} else {
					showName = user.uname;
				}
			} else {
				showName = user.realname;
			}
			return showName;
		}

		//加载数据
		function loadData() {
			var param = {
				group_id : api.pageParam.group_id,
				pid : api.pageParam.pid,
				cid : api.pageParam.cid,
				vid : api.pageParam.chapterid,
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
			};
			cfnetppPOST(url_getClassDissussList, param, false, function(data, status) {
				hideProgress();
				api.refreshHeaderLoadDone();
				if (api.pageParam.group_id == '' || api.pageParam.group_id == 'null' || api.pageParam.group_id == 0) {
					$('#noTeam').show();
					$('#contentDiv').hide();
				} else {
					$('#noTeam').hide();
					$('#contentDiv').show();
					if (status == 'success') {
						if (page == 1) {
							//存储最后刷新的一次时间戳
							saveTimeStamp();
						}
						$('#noNet').hide();
						var people = data.data.name;
						htmlStringWithClass(people);
						if (data.code == 200) {
							$('#noData').hide();
							var list = data.data.list;
							dataLen = data.data.total;
							$('#num').text(dataLen);
							if (list != null && list.length > 0) {
								refreshCount = list.length;
								var listArr = new Array();
								var htmlString = new String();
								if (page == 1) {
									for (var i = 0; i < list.length; i++) {
										var weeklyData = list[i];
										var data = {
											uid : weeklyData.uid,
											id : weeklyData.id,
											userimg : weeklyData.picurl,
											username : weeklyData.rename,
											content : weeklyData.content,
											num : weeklyData.num,
											ctime : weeklyData.ctime
										};
										listArr.push(data);
										htmlString += htmlStringWithName(data, i);
									}
									dataArr = listArr;
									$('#list_discus').html(htmlString);
								} else {
									var oldCount = dataArr.length;
									for (var i = 0; i < list.length; i++) {
										var index = oldCount + i;
										var weeklyData = list[i];
										var data = {
											uid : weeklyData.uid,
											id : weeklyData.id,
											userimg : weeklyData.picurl,
											username : weeklyData.rename,
											content : weeklyData.content,
											num : weeklyData.num,
											ctime : weeklyData.ctime
										};
										listArr.push(data);
										htmlString += htmlStringWithName(data, index);
									}
									dataArr = dataArr.concat(listArr);
									$('#list_discus').append(htmlString);
								}
							} else {
								if (page == 1) {
									//								$('#noData').show();
									$('#noTeam').hide();
								} else {
									api.toast({
										msg : '暂无数据',
										duration : 2000,
										location : 'bottom'
									});
								}
								$('#list_discus').html('');
							}
						} else if (data.code == 108) {
							//						if (page == 1) {
							$('#num').text('0');
							$('#list_discus').html('');
							//							$('#noData').show();
							//							$('#noTeam').show();
							//						}
						} else if (data.code == 109) {
							$('#num').text('0');
							$('#list_discus').html('');
							//							$('#noData').show();
							//							$('#noTeam').show();
							//
						} else {
							//						if (page == 1) {
							$('#list_discus').html('');
							//							$('#noData').show();
							//							$('#noTeam').hide();
							//						}
						}
					} else {
						$('#noTeam').hide();
						$('#noNet').show();
					}
				}
			});
			//			}
		}

		//拼接人员页面ui
		function htmlStringWithClass(list) {
			var strArr = []
			$('#people').html('');
			for (var i = 0; i < list.length; i++) {
				var u_name = selectName(list[i]);
				strArr.push(u_name);
			}
			$('#people').html(strArr.toString());
		}

		//拼接讨论列表ui
		function htmlStringWithName(list, index) {
			var spanStr = '';
			var imgStr = '';
			if (list.userimg == null || list.userimg == '') {
				imgStr = '../../icon/icon_default_HeadPortrait.png';
			} else {
				imgStr = list.userimg;
			}
			if (list.uid == $api.getStorage('cfnetppuid')) {
				spanStr = '<td class="Comment" onclick="showAlert(' + list.id + ')"><img class="incon_samll" src="../../image/icon_shanchu.png"/ ><span class="left_5">删除</span></td>';
			} else {
				spanStr = '';
			}
			return '<li dataid="' + index + '" class="mui-table-view-cell mui-media list_item" >' + '<div >' + '<img class="mui-media-object mui-pull-left cell_user_icon" src="' + imgStr + '" style="display: block">' + '<p class=" base_content_font base_dark_grey" >' + '<span>' + list.username + '</span>' + '<span class="left_5 font10">' + timestampFormat(list.ctime) + '</span>' + '</p>' + '<div class="Commentbody top_2 ">' + '<p class="word-break left_50">' + htmlspecialchars_decode(list.content) + '</p>' + '</div>' + '</div>' + '<table class="MBToolBar top_5 ">' + '<tr>' + spanStr + '</tr>' + '</table>' + '</li>';
		}

		function showAlert(id) {
			event.stopPropagation();
			$('#offlineAlert').show();
			Itemid = id;
		}

		//取消
		function cleanCancel() {
			$('#offlineAlert').hide();
		}

		//确定
		function cleanConfirm() {
			$('#offlineAlert').hide();
			deleteDiscus(Itemid);
			Itemid = "";
		}

		//删除评论
		function deleteDiscus(id) {
			var param = {
				id : id,
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
			};
			cfnetppPOST(url_deleteDiscuss, param, true, function(data, status) {
				hideProgress();
				SendBusinessOperationsLogNotifi('小组讨论列表页', '035', param, param, '', data, '小组讨论删除讨论', '035-04')
				if (status == 'success') {
					if (data.code == 200) {
						ShowToast('删除成功');
						Itemid = "";
						loadNewData();
					} else {
						api.toast({
							msg : '删除失败',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					api.toast({
						msg : '获取数据失败',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}

		//编辑评论
		function EditDiscus(index) {
			event.stopPropagation();
			var data = dataArr[parseInt(index)];
			var id = data.id;
			var content = data.content;
			api.openFrame({
				name : 'New_FreeCourse_EditDiscus',
				url : 'New_FreeCourse_EditDiscus.html',
				pageParam : {
					id : id,
					pid : api.pageParam.pid,
					title : data.title,
					chapterid : api.pageParam.chapterid,
					content : content
				}
				//
			});
		}

		//列表条目点击
		function openReplayWin(index) {
			event.stopPropagation();
			var data = dataArr[parseInt(index)];
			var id = data.id;
			var userimg = data.userimg;
			api.openWin({useWKWebView:true,
				name : 'New_Student_Study_DiscussChapterReplayWindow',
				url : 'New_Student_Study_DiscussChapterReplayWindow.html',
				pageParam : {
					data : data,
					title : api.pageParam.cdetailtitle,
					pid : api.pageParam.pid,
					cid : api.pageParam.cid,
					chapterid : api.pageParam.chapterid,
					type : 0
				}
			});
		}
	</script>
</html>